package com.shujia.bigdata.word;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;

public class WordCount {
    public static void main(String[] args) throws Exception {

        /**
         * 统计每个单词出现的次数
         *
         */

        HashMap<String, Integer> map = new HashMap<>();


        //1、读取文件

        FileReader fileReader = new FileReader("java/data/word/0");
        BufferedReader bufferedReader = new BufferedReader(fileReader);

        String line;
        while ((line = bufferedReader.readLine()) != null) {

            String[] split = line.split(",");

            for (String word : split) {

                Integer integer = map.get(word);
                if (integer == null) {
                    map.put(word, 1);
                } else {
                    map.put(word, integer + 1);
                }

            }
        }

        System.out.println(map.size());


    }
}
